package com.yidu.boss.sys.service.impl;

import com.yidu.boss.sys.dao.CustodianMapper;
import com.yidu.boss.sys.domain.Custodian;
import com.yidu.boss.sys.domain.CustodianExample;
import com.yidu.boss.sys.service.CustodianService;
import com.yidu.boss.util.RandomString;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

/**
 * @Auther:si
 * @Date:2019/11/22
 * @Description:com.yidu.boss.sys.service.impl
 * @Version:1.0
 */
@Service
public class CustodianServiceImpl implements CustodianService {
    //定义管理人接口
    @Autowired
    private CustodianMapper custodianMapper;

    /**
     * 用来给外表连接使用 //查询所有给基金表使用
     * @return
     */
    @Override
    public List<Custodian> selectAll() {
        return custodianMapper.selectAll();
    }

    /**
     * 根据条件查询所有
     * @param custodianExample
     * @return
     */
    @Override
    public List<Custodian> selectByExample(CustodianExample custodianExample) {
        return custodianMapper.selectByExample(custodianExample);
    }

    /**
     * 模糊查询
     *
     * @param condition
     * @return
     */
    public List<Custodian> selectLike(String condition) {
        CustodianExample custodianExample = new CustodianExample();
        //模糊查询名字
        custodianExample.or().andCustodiannameLike(condition);
        //集合
        List<Custodian> custodianList = custodianMapper.selectByExample(custodianExample);
        return custodianList;
    }

    /**
     * 模糊查询所有
     * @param condition
     * @return
     */
    @Override
    public List<Custodian> selectSomeByMore(String condition) {
        //调用业务层模糊查询所有的方法
        List<Custodian> custodianList = custodianMapper.selectSomeByMore(condition);
        return custodianList;
    }

    /**
     * 添加
     * @param custodian
     * @return
     */
    @Override
    public int insertCustodian(Custodian custodian) {
        //Id
        custodian.setCustodianid(RandomString.getUUID());
        System.out.println("custodian = " + custodian);
        int i = custodianMapper.insertSelective(custodian);
        return i;
    }

    /**
     * 修改
     * @param custodian
     * @return
     */
    @Override
    public int updateCustodian(Custodian custodian) {
        //Example类
        CustodianExample custodianExample =new CustodianExample();
        //获得Id
        custodianExample.or().andCustodianidEqualTo(custodian.getCustodianid());
        int i =custodianMapper.updateByExampleSelective(custodian,custodianExample);
        return i;
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @Override
    public int deleteCustodian(String id) throws DataAccessException {
        int i =custodianMapper.deleteByPrimaryKey(id);
        //System.err.println("i = " + i);
        return i;
    }


}
